﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.Outstorage
{
    public partial class ListReturnGoods : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                    Bind(user_id);
                }

            }

        }

        private void Bind(int user_id)
        {
            string strWhere = " user_id=" + user_id;

            if (!string.IsNullOrEmpty(this.txt_proid.Text))
            {
                strWhere += " and proid like '%"+txt_proid.Text+"%' ";
            }

            if (!string.IsNullOrEmpty(this.txt_material.Text))
            {
                strWhere += " and material like '%" + txt_material.Text + "%' ";
            }

            if (!string.IsNullOrEmpty(this.txt_returnNo.Text))
            {
                strWhere += " and returnNo like '%" + txt_returnNo.Text + "%' ";
            }

            DataSet ds = new dzs.BLL.returnGoods().GetList(strWhere);

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        //查询
        protected void btn_sel_Click(object sender, EventArgs e)
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                Bind(user_id);
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_print")
            {
                string returnNo = e.CommandArgument.ToString();

                if (!string.IsNullOrEmpty(returnNo))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>OpenPopWin('PrintReturnGoods.aspx?returnNo=" + returnNo + "','600px','800px');</script>");
                }
               
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
                Bind(user_id);
            }
        }
    }
}